package com.example.forum.controller;

import com.example.forum.common.AppResult;
import com.example.forum.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: liuli
 * Date: 2024-08-06
 * Time: 15:42
 */

@Api(tags = "测试类相关接⼝")
//表示返回的结果是数据
@RestController
//定义一级映射路径
@RequestMapping("/test")
public class TestController {
       @ApiOperation("接口测试1，显示hello")
        @GetMapping("/hello")
        public String  hello(){
            return "hello!";
        }

       @ApiOperation("接口测试2，显示抛出的异常信息")
        @GetMapping("/exception")
        public AppResult testException() throws Exception{
            throw new Exception("Exception出现咯...");
        }

       @ApiOperation("接口测试2，显示自定义的异常信息")
        @GetMapping("/appException")
        public AppResult testApplicationException() {
            throw new ApplicationException("ApplicationException出现咯...");
        }


        @ApiOperation("接口测试4，根据上传的姓名显示hello信息")
        @PostMapping("/helloByName")
        public String helloByName (@ApiParam(value = "姓名") @RequestParam("name") String name){
            return  "hello:" + name;
        }



}


